<template>
    <div class="app-container">
        <div class="head">
            <img src="@/assets/img/Layout/position.png" />
            <p class="see-block">采购退货列表</p>
        </div>
        <div class="view-container">
            <el-form :model="queryParams" ref="queryForm" :inline="true">
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="供应商" prop="searchValue">
                            <el-input
                                v-model="queryParams.searchValue"
                                placeholder="请输入供应商"
                                clearable
                                size="small"
                                @keyup.enter.native="handleQuery"
                            />
                        </el-form-item>
                        <el-form-item label="采购退货单号" prop="code">
                            <el-input
                                v-model="queryParams.code"
                                placeholder="请输入采购退货单号"
                                clearable
                                size="small"
                                @keyup.enter.native="handleQuery"
                            />
                        </el-form-item>
                        <el-form-item label="业务日期" prop="time">
                            <el-date-picker
                                v-model="time"
                                type="daterange"
                                range-separator="至"
                                style="width: 230px;"
                                @change="dataTime()"
                            >
                            </el-date-picker>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" class="list-search btn-success" color="#5ED4D4">检索</el-button>
                            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery" class="list-search">重置</el-button>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="源采购单号" prop="purchaseOrderCode">
                            <el-input
                                v-model="queryParams.purchaseOrderCode"
                                placeholder="请输入源采购单号"
                                clearable
                                size="small"
                                @keyup.enter.native="handleQuery"
                            />
                        </el-form-item>
                        <el-form-item label="产品名称或代码" prop="searchParam">
                            <el-input
                                v-model="queryParams.searchParam"
                                placeholder="请输入产品名称或代码"
                                clearable
                                size="small"
                                @keyup.enter.native="handleQuery"
                            />
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                    <el-button
                        class="btn-success"
                        type="primary"
                        icon="el-icon-plus"
                        size="mini"
                        @click="add()"
                        v-hasPermi="['system:purchaseReturnOrder:add']"
                    >订单新建</el-button>
                </el-col>
            </el-row>
            <el-table :data="list" @row-click="handleView" border>
                <el-table-column label="序号" type="index" align="center" width="50">
                    <template slot-scope="scope">
                        <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="订单编码"  align="center" prop="code" width="150px" />
                <el-table-column label="供应商" align="center" prop="supplierName" width="150px" />
                <el-table-column label="产品编码" align="center" prop="specificationCode" width="150px">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.purchaseReturnOrderDetailList" :key="index">
                            {{ item.productBasicCode }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="产品名称" align="center" prop="specificationName" width="180px">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.purchaseReturnOrderDetailList" :key="index">
                            {{ item.productBasicName }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="SKU编码" align="center" prop="specificationCode" width="150px">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.purchaseReturnOrderDetailList" :key="index">
                            {{ item.specificationCode }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="SKU名称" align="center" prop="specificationName" width="180px">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.purchaseReturnOrderDetailList" :key="index">
                            {{ item.specificationName }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="简称" align="center" prop="productShortName" width="180px">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.purchaseReturnOrderDetailList" :key="index">
                            {{ item.productShortName }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="规格" align="center" prop="specification" width="150px">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.purchaseReturnOrderDetailList" :key="index">
                            {{ item.specification }}
                        </div>
                    </template>
                </el-table-column>
                <!-- <el-table-column label="批次" align="center" prop="batchNumber">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.purchaseReturnOrderDetailList" :key="index">
                            {{ item.batchNumber }}
                        </div>
                    </template>
                </el-table-column> -->
                <el-table-column label="申退数量" align="center" prop="planNum">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.purchaseReturnOrderDetailList" :key="index">
                            {{ item.planNum }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="单位" align="center" prop="unit">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.purchaseReturnOrderDetailList" :key="index">
                            {{ item.unit }}
                        </div>
                    </template>
                </el-table-column>
                <!-- <el-table-column label="未税单价" align="center" prop="untaxedUnitPrice">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.purchaseReturnOrderDetailList" :key="index">
                            {{ item.untaxedUnitPrice }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="未税金额" align="center" prop="untaxedAmount">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.purchaseReturnOrderDetailList" :key="index">
                            {{ item.untaxedAmount }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="含税单价" align="center" prop="taxedUnitPrice">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.purchaseReturnOrderDetailList" :key="index">
                            {{ item.taxedUnitPrice }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="税率" align="center" prop="taxRate">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.purchaseReturnOrderDetailList" :key="index">
                            {{ item.taxRate }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="税额" align="center" prop="levy">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.purchaseReturnOrderDetailList" :key="index">
                            {{ item.levy }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="价税合计" align="center" prop="totalTax">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.purchaseReturnOrderDetailList" :key="index">
                            {{ item.totalTax }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="赠品" align="center" prop="isGift" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.purchaseReturnOrderDetailList" :key="index">
                            {{ item.isGift == 0 ? '否' : '是' }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="实际退库" align="center" prop="warehouseOut">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.purchaseReturnOrderDetailList" :key="index">
                            {{ item.warehouseOut }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="实际成本" align="center" prop="actualCost">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.purchaseReturnOrderDetailList" :key="index">
                            {{ item.actualCost }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="到货日期" align="center" prop="arrivalDate" width="180px">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.purchaseReturnOrderDetailList" :key="index">
                            {{ item.arrivalDate }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="关联申请单号" align="center" prop="requisitionNumber" width="150px">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.purchaseReturnOrderDetailList" :key="index">
                            {{ item.requisitionNumber }}
                        </div>
                    </template>
                </el-table-column> -->
                <el-table-column label="状态" align="center" prop="approvalStatus">
                    <template slot-scope="scope">
                        <div v-if="scope.row.approvalStatus == 0" style="color:#13C2C2">待审核</div>
                        <div v-if="scope.row.approvalStatus == 1" style="color:#52C41A">已审核</div>
                        <div v-if="scope.row.approvalStatus == 2" style="color:#fd562c">反审核</div>
                        <div v-if="scope.row.approvalStatus == 3" style="color:#fd562c">拒绝</div>
                        <div v-if="scope.row.approvalStatus == null" style="color:#13C2C2">草稿</div>
                    </template>
                </el-table-column>
                <el-table-column label="备注" align="center" prop="remark">
                    <template slot-scope="scope">
                        <div v-for="(item, index) in scope.row.purchaseReturnOrderDetailList" :key="index">
                            {{ item.remark }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                    <template slot-scope="scope">
                        <el-button
                            size="mini"
                            type="text"
                            icon="el-icon-delete"
                            @click.native.stop="handleDelete(scope.row)"
                            v-hasPermi="['system:purchaseReturnOrder:remove']"
                        >删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <pagination
                v-show="total > 0"
                :total="total"
                :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize"
                @pagination="getList"
            />
        </div>
    </div>
</template>

<script>
import { returnList, returnDelete } from "@/api/system/purchaseReturn/purchaseReturn"
export default {
    name: "list",
    data() {
        return {
            // 总条数
            total: 0,
            // 列表数据
            list: [],
            time: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                startTime: '',
                endTime: '',
                code: '', // 采购退货单号
                searchValue: '', // 供应商
                searchParam: '', // 产品名称
                purchaseOrderCode: '', // 源采购单号
            }
        }
    },
    created() {
        this.getList()
    },
    methods: {
        // 获取列表
        getList() {
            returnList(this.addDateRange(this.queryParams)).then(res => {
                this.list = res.rows
                this.total = res.total
            })
        },
        // 时间选择器
        dataTime(){
            if(this.time){
                let day = 24 * 60 * 60 * 1000
                this.queryParams.startTime = this.parseTime(this.time[0])
                this.queryParams.endTime = this.parseTime(this.time[1].getTime() + day)
            }else if(this.time == null){
                this.queryParams.startTime = ''
                this.queryParams.endTime = ''
            }
        },
        // 搜索按钮
        handleQuery() {
            this.queryParams.pageNum = 1
            this.getList()
        },
        // 重置按钮
        resetQuery() {
            this.resetForm("queryForm")
            this.time = ''
            this.queryParams.startTime = ''
            this.queryParams.endTime = ''
            this.handleQuery()
        },
        // 新建
        add(){
            this.$router.push({path:"/purchase/purchaseReturn/add"})
        },
        // 查看
        handleView(row) {
            this.$router.push({path:"/purchase/purchaseReturn/detail", query:{ id: row.id }})
        },
        // 删除
        handleDelete(row){
            this.$modal.confirm('是否确认删除？').then(() => {
                returnDelete(row.id).then(() => {
                    this.getList()
                    this.$modal.msgSuccess("删除成功")
                })
            }).catch(() => {})
        },
    }
}
</script>
